#include "SList.h"

void Test()
{
	SLTNode* d1 = (SLTNode*)malloc(sizeof(SLTNode));
	assert(d1);
	SLTNode* d2 = (SLTNode*)malloc(sizeof(SLTNode));
	assert(d2);
	SLTNode* d3 = (SLTNode*)malloc(sizeof(SLTNode));
	assert(d3);

	d1->data = 1;
	d2->data = 2;
	d3->data = 3;
	

	d1->next = d2;
	d2->next = d3;
	d3->next = NULL;
	
	SListPrint(d1);
}


void Test1()
{
	SLTNode * plist = NULL;

	SListPushBack(&plist, 1);
	SListPrint(plist);

	SListPushBack(&plist, 2);
	SListPrint(plist);

	SListPushBack(&plist, 3);
	SListPrint(plist);


}

void Test2()
{
	SLTNode *plist = NULL;
	SListPushBack(&plist, 1);
	SListPushBack(&plist, 10);
	SListPushBack(&plist, 100);
	SListPushBack(&plist, 1000);

	SListPopBack(&plist);

	SListPrint(plist);

}

void Test3()
{
	SLTNode *plist = NULL;
	SLTNode *ret = NULL;
	SListPushBack(&plist, 1);
	SListPushFrond(&plist, 10);
	SListPushBack(&plist, 100);
	SListPushFrond(&plist, 1000);
	SListPrint(plist);

	ret = SListFind(plist, 10);
	SListInsertBefore(&plist, ret, 99);
	SListInsertAfter(ret, 999);
	SListPrint(plist);

}

void Test4()
{
	SLTNode *plist = NULL;
	SLTNode *ret = NULL;
	SListPushBack(&plist, 1);
	SListPushFrond(&plist, 10);
	SListPushBack(&plist, 100);
	SListPushFrond(&plist, 1000);
	SListPrint(plist);

	ret = SListFind(plist, 10);
	SListInsertBefore(&plist, ret, 99);
	SListInsertAfter(ret, 999);
	SListPrint(plist);

	ret = SListFind(plist,1000);
	SListErase(&plist, ret);
	SListPrint(plist);

}

void Test5()
{
	SLTNode *plist = NULL;
	SLTNode *ret = NULL;
	
	SListPushFrond(&plist, 9);
	ret = SListFind(plist, 9);
	SListInsertBefore(&plist,ret, 99);
	SListPrint(plist);
	SListInsertAfter(ret, 999);
	SListPrint(plist);

	SListErase(&plist, ret);

	SListPrint(plist);

	ret = SListFind(plist, 99);
	SListEraseAfter(ret);
	SListPrint(plist);
}

void Test6()
{
	SLTNode *plist = NULL;
	SLTNode *ret = NULL;

	SListPushFrond(&plist, 9);
	SListPushBack(&plist, 99999);
	SListPrint(plist);
	SListPopBack(&plist);
	SListPrint(plist);
	ret = SListFind(plist, 9);
	SListModify(ret, 999);
	SListPrint(plist);
}

void SListPushBack1(SLTNode *pphead, SLTDataType x)
{
	SLTNode* newnode = BuySListNode(x);

	if (pphead == NULL)
	{
		pphead = newnode;
	}
	else
	{
		SLTNode* cur = pphead;
		while (cur->next)
		{
			cur = cur->next;
		}
		cur->next = newnode;
	}
}

void Test7()
{
	SLTNode *plist = NULL;
    SListPushBack1(plist, 5);
}

void SListPushFrond1(SLTNode **pphead, SLTDataType x)
{
	SLTNode* newnode = BuySListNode(x);
	*pphead = newnode;
	newnode->next = *pphead;
	
}

void Test8()
{
	SLTNode *plist = NULL;
	SListPushBack(&plist, 1);
	SListPushBack(&plist, 2);
	SListPrint(plist);
	//SListPushFrond1(&plist, 3);
	SListPrint(plist);

}

int main()
{
	Test8();
	return 0;
}